package fei.yuzhi.com.loveflowers.fragment.firstpagefragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import fei.yuzhi.com.loveflowers.R;

/**
 * Created by My on 2016/10/8.
 */
public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private List<String> imageUrlList;
    static final int firstGird = 1;
    static final int othergrid = 2;
    private int LayoutNum;
    public GridViewAdapter(Context context,List<String> imageUrlList,int LayoutNum){
        this.context=context;
        this.imageUrlList=imageUrlList;
        this.LayoutNum=LayoutNum;
    }
    @Override
    public int getCount() {
        return imageUrlList.size();
    }

    @Override
    public Object getItem(int position) {
        return imageUrlList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            if (LayoutNum==firstGird){
                convertView= LayoutInflater.from(context).inflate(R.layout.item_firstpage_first_gird,null);
                holder=new ViewHolder();
                holder.iv= (ImageView) convertView.findViewById(R.id.item_first_gridrv_iv);
                convertView.setTag(holder);
            }else if (LayoutNum==othergrid){
                convertView= LayoutInflater.from(context).inflate(R.layout.item_firstpage_other_gird,null);
                holder=new ViewHolder();
                holder.iv= (ImageView) convertView.findViewById(R.id.item_other_gridrv_iv);
                convertView.setTag(holder);
            }
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(imageUrlList.get(position)).into(holder.iv);
        return convertView;
    }
    static class ViewHolder{
        ImageView iv;
    }
}
